﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestAssignBoolean.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.RMFlattenDenseMatrixTest
{
    #region Usings

    using System;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for
    ///     <see cref="RMFlattenDenseMatrixExtensions.Assign(RMFlattenDenseMatrix{bool},RMFlattenDenseMatrix{bool})"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.RMFlattenDenseMatrixExtensions")]
    public sealed class TestAssignBoolean
    {
        /// <summary>
        ///     Tests the method when source and target have the same size.
        /// </summary>
        [Test]
        public void WhenSourceAndTargetHaveTheSameSize()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 true, true, true,
                                 true, true, true
                             };
            var source = new RMFlattenDenseMatrix<bool>(2, 3, sourceData);
            var targetData = new[]
                             {
                                 false, false, false,
                                 false, false, false
                             };
            var target = new RMFlattenDenseMatrix<bool>(2, 3, targetData);

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(sourceData));
        }

        /// <summary>
        ///     Tests the method when source has less count of rows than target.
        /// </summary>
        [Test]
        public void WhenSourceHasLessRowsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 true, true, true
                             };
            var source = new RMFlattenDenseMatrix<bool>(1, 3, sourceData);
            var targetData = new[]
                             {
                                 false, false, false,
                                 false, false, false
                             };
            var target = new RMFlattenDenseMatrix<bool>(2, 3, targetData);
            var expectedResult = new[]
                                 {
                                     true, true, true,
                                     false, false, false
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when source has greater count of rows than target.
        /// </summary>
        [Test]
        public void WhenSourceHasGreaterRowsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 true, true, true,
                                 true, true, true,
                                 true, true, true
                             };
            var source = new RMFlattenDenseMatrix<bool>(3, 3, sourceData);
            var targetData = new[]
                             {
                                 false, false, false,
                                 false, false, false
                             };
            var target = new RMFlattenDenseMatrix<bool>(2, 3, targetData);
            var expectedResult = new[]
                                 {
                                     true, true, true,
                                     true, true, true
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when source has less count of columns than target.
        /// </summary>
        [Test]
        public void WhenSourceHasLessColumnsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 true, true,
                                 true, true
                             };
            var source = new RMFlattenDenseMatrix<bool>(2, 2, sourceData);
            var targetData = new[]
                             {
                                 false, false, false,
                                 false, false, false
                             };
            var target = new RMFlattenDenseMatrix<bool>(2, 3, targetData);
            var expectedResult = new[]
                                 {
                                     true, true, false,
                                     true, true, false
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when source has greater count of columns than target.
        /// </summary>
        [Test]
        public void WhenSourceHasGreaterColumnsCountThanTarget()
        {
            // Arrange
            var sourceData = new[]
                             {
                                 true, true, true, true,
                                 true, true, true, true
                             };
            var source = new RMFlattenDenseMatrix<bool>(2, 4, sourceData);
            var targetData = new[]
                             {
                                 false, false, false,
                                 false, false, false
                             };
            var target = new RMFlattenDenseMatrix<bool>(2, 3, targetData);
            var expectedResult = new[]
                                 {
                                     true, true, true,
                                     true, true, true
                                 };

            // Act
            target.Assign(source);

            // Assert
            Assert.That(target.Values, Is.Not.SameAs(source.Values) & Is.EquivalentTo(expectedResult));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when source is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenSourceIsNull()
        {
            // Arrange
            var target = new RMFlattenDenseMatrix<bool>(2, 3);

            // Act and Assert
            Assert.That(
                () => target.Assign(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("source"));
        }

        /// <summary>
        ///     Tests the method when target is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenTargetIsNull()
        {
            // Arrange
            var source = new RMFlattenDenseMatrix<bool>(2, 3);

            // Act and Assert
            Assert.That(
                () => RMFlattenDenseMatrixExtensions.Assign(null, source),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("target"));
        }

#endif
    }
}